package com.qft.rnlearn;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        String extras = getIntent().getStringExtra("extras");
        TextView tv_msg = findViewById(R.id.tv_msg);
        tv_msg.setText(extras);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_ok:
                Intent intent = new Intent();
                intent.putExtra("data", "点击了确定");
                setResult(RESULT_OK, intent);
                finish();
                break;

            case R.id.btn_cancel:
                setResult(RESULT_CANCELED);
                finish();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        setResult(RESULT_CANCELED);
        super.onBackPressed();
    }
}
